// pages/activity_detail/activity_detail.js

var WxParse = require('../../wxParse/wxParse.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activity: [],
    selected: true,
    selected1: false,
    qisuid: '',
    ztnr: '',
    isShowTabActive: false,
    title: ""
  },


  /**
   * 生命周期函数--监听页面加载
   */

  onLoad: function(options) {
  console.log(options)
    if (options.areaid) {
      wx.setStorageSync('areaid', options.areaid)
    }
    if (options.cityName){
      wx.setStorageSync('cityName', options.cityName)
    }
    if (options.ids){
      wx.setStorageSync('ids', options.ids)
    }
    console.log(777, wx.getStorageSync('ids'))

    if (options.scene) {
      var scene = decodeURIComponent(options.scene).split('&')
      var res = []
      for (var k in scene) {
        res.push(scene[k].split('='))
      }
      console.log(res)
      wx.setStorageSync('ids', res[0][1])
      wx.setStorageSync('areaid', res[1][1])
    }

    var that = this;
    that.setData({
      scrollHeight: wx.getSystemInfoSync().windowHeight
    })
    this.detailReques()
  },
  onShareAppMessage: function (res) {
    console.log(wx.getStorageSync('areaid'))
    console.log(555888)

    console.log(wx.getStorageSync('cityName'))
    return {
      title: this.data.title,
      desc: "这是描述",
      path: "/pages/activity_detail/activity_detail?areaid=" + wx.getStorageSync('areaid') +
        "&cityName=" + wx.getStorageSync('cityName') + '&ids=' + wx.getStorageSync('ids')
    }
  },

  detailReques: function() {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    console.log("请求进入", wx.getStorageSync('areaid'))
    var url="https://miniapp.odeman.com/summercamp/active_detail.php?areaid=" + wx.getStorageSync('areaid') + '&itemid=' + wx.getStorageSync('ids')
    wx.request({
      url:url,
      header: {
        'Content-Type': 'application/json'
      },
      success: function(res) {
        console.log(res)
        console.log(res.data.title)
    
        console.log(url)
        wx.hideLoading()
        var ztnr = res.data.ztnr;
        var ztnrTest = WxParse.wxParse('ztnr', 'html', ztnr, that, 5);

        var kcb = res.data.kcb;
        var kcbTest = WxParse.wxParse('kcb', 'html', kcb, that, 5);

        var cyxz = res.data.cyxz;
        var cyxzTest = WxParse.wxParse('cyxz', 'html', cyxz, that, 5);
        that.setData({
          activity: res.data,
          banners: res.data.banners,
          qisuid: res.data.qs[0].id || "",
          sign_index: res.data.qs[0].id,
          ztnr: ztnrTest,
          kcb: kcbTest,
          cyxz: cyxzTest,
          pf: res.data.pf,
          pl: res.data.pl,
          isfly: res.data.isfly,
          moredata: res.data.moredata,
          title:res.data.title

        })
        wx.setNavigationBarTitle({
          title: res.data.title
        })
      }
    })

  },

  scroll: function(e) {
    if (e.detail.scrollTop > 1000) {
      this.setData({
        isShowTabActive: true
      })
    } else {
      this.setData({
        isShowTabActive: false
      })
    }
  },
  footerNav: function(e) {
    var areaid = app.appData.areaid;

    var id = e.currentTarget.dataset.id;
    if (id == 1) {
      wx.navigateTo({
        url: '../index/index?areaid=' + areaid,
      })
    } else if (id == 2) {
      wx.navigateTo({
        url: '../activity_list/activity_list?areaid=' + areaid,
      })
    } else {
      wx.navigateTo({
        url: '../user/user?areaid=' + areaid + '&userid=' + wx.getStorageSync('userid'),
      })
    }

  },
  toDetail(e) {
    var itemid = e.currentTarget.dataset.itemid
    wx.setStorageSync('ids', itemid)
    wx.navigateTo({
      url: '../activity_detail/activity_detail',
    })
  },
  selected: function(e) {
    this.setData({
      selected1: false,
      selected2: false,
      selected: true,
      selected3: false,
    })
  },
  selected1: function(e) {
    this.setData({
      selected: false,
      selected2: false,
      selected1: true,
      selected3: false,
    })
  },
  selected2: function(e) {
    this.setData({
      selected: false,
      selected1: false,
      selected2: true,
      selected3: false,
    })
  },
  selected3: function(e) {
    this.setData({
      selected: false,
      selected1: false,
      selected2: false,
      selected3: true,
    })
  },

  //期数选着
  signqs: function(e) {
    var that = this;
    var qsid = e.currentTarget.dataset.qsid;
    that.setData({
      qisuid: qsid,
      sign_index: qsid
    })

  },

  //报名选着
  // signup: function() {
  //   var qisuid = this.data.qisuid;
  //   wx.setStorageSync('qsid', qisuid)
  //      wx.navigateTo({
  //       url: '../SignUps/SignUps',
  //     })
  // },
  signup: function() {
    var qisuid = this.data.qisuid;
    wx.setStorageSync('qsid', qisuid);
    var _this = this
    var isUserid = wx.getStorageSync('userid')
    if (!isUserid) {
      wx.navigateTo({
        url: '/pages/login/login',
      })
    } else {
      wx.navigateTo({
        url: '../SignUps/SignUps'
      });
    }

  },
  return_index: function() {
    wx.navigateTo({
      url: '/pages/index_index/index_index',
    })
  },
  ydtap: function() {
    wx.navigateTo({
      url: '/pages/camp/camp'
    })
  },

  homepage: function(e) {
    wx.navigateTo({
      url: '/pages/personalHomepage/personalHomepage'
    })
  }

})